package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/15 20:10
 **/
public class Day30_2_Num34_SearchRange {
    class Solution {
        public int[] searchRange(int[] nums, int target) {
            int left = BinSearch(nums,target);
            int right = BinSearch(nums,target+1);
            if(left == nums.length || nums[left] != target){
                return new int[]{-1,-1};
            }
            return new int[]{left,right-1};
        }
        private int BinSearch (int[] nums, int target){
            int left = 0, right = nums.length;
            int mid;
            while(left < right){
                mid = left + ((right - left)>>1);
                if(nums[mid] >= target){
                    right = mid;
                }else left = mid + 1;
            }
            return left;
        }
    }
}